define(function () {

    var self,footData={
        index:0
    };

    var gwat600 = app.Module.extend({

        init: function () {
            self = this;
            self.mData = {};
            self.searchData = {
                keyword: ''
            };
            self._super({
                _tag: 'p_gwat600', // key, 对象放进pageModule
                _sliderId: 'slider', // tabs
                _refreshAutoInit: true //自动加载刷新控件
            }, win);

            mui.ready(function () {
                Vue.component('gwat600-listitem', {
                    template: app.getByid(doc, 'item-template'),
                    props: {
                        model: Array
                    },
                    methods: {
                        statueN: function(item){
                            if(item.GWCVDOCNO == null){
                                return true;
                            }else{
                                return false;
                            }
                        },
                        statueY: function(item){
                            if(item.GWCVDOCNO != null){
                                return true;
                            }else{
                                return false;
                            }
                        },
                        statueImg: function(item){
                            if(item.GWCVDOCNO != null){
                                return 'reser';
                            }else{
                                return 'nonReser';
                            }
                        },
                        confirm: function (item) {
                            app.openPage({
                                src: "gwat600/gwat600_01.html",
                                argsKey: 'gwat600_01_page',
                                args: item
                            });
                        },
                        reconfirm: function (item) {
                            app.confirm({
                                msg: '是否取消回报？',
                                ok: function (e) {
                                    app.ajax({
                                        xurl: "api/wx/gwat600/reconfirm",
                                        // xtime: '1d',
                                        xdata: {
                                            item:JSON.stringify(item)
                                        },
                                        cb: function (result) {
                                            if (result.ok) {
                                                self._getRefreshObj().data.remove(item);
                                                app.toast('取消回报成功');
                                            }else{
                                                app.toast(result.data.message);
                                            }
                                        }
                                    });
                                }
                            });
                        }
                    }
                });

                new Vue({
                    el: doc.getElementById('footer'),
                    data: footData,
                    methods: {
                        checkall : function(){
                            var items = self._getRefreshObj().data;
                            for(var i=0;i<items.length;i++){
                                items[i].checked = true;
                                if(items[i].GWCVACTI == 'N'){
                                    items[i].GWCV006 = '';
                                    items[i].GWCV009 = '';
                                    items[i].GWCV010 = '';
                                    items[i].GWCV050 = '';
                                }
                            }
                        },
                        confirmlist : function(){
                            var items = [];
                            var list = self._getRefreshObj().data;
                            for(var i=0;i<list.length;i++){
                                if(list[i].checked == true){
                                    items.push(list[i])
                                }
                            }
                            if(items.length == 0){
                                app.toast('无选中项');
                                return;
                            }
                            app.confirm({
                                msg: '是否回报？',
                                ok: function (e) {
                                    app.ajax({
                                        xurl: "api/wx/gwat600/confirmlist",
                                        xdata: {
                                            items :JSON.stringify(items)
                                        },
                                        cb: function (result) {
                                            for(var i=0;i<result.data.data.length;i++){
                                                for(var j=0;j<items.length;j++){
                                                    if(items[j].GWCS010== result.data.data[i].GWCS010
                                                        && items[j].GWCS008== result.data.data[i].GWCS008
                                                        && items[i].GWCS001 == item.GWCS001
                                                        && items[i].GWCS019 == item.GWCS019){
                                                        list.remove(items[j]);
                                                    }
                                                }
                                            }
                                            if (result.ok) {
                                                app.toast('批量回报成功');
                                            }else{
                                                app.toast(result.data.message);
                                            }
                                        }
                                    });
                                }
                            });
                        },
                        reconfirmlist : function(){
                            var items = [];
                            var list = self._getRefreshObj().data;
                            for(var i=0;i<list.length;i++){
                                if(list[i].checked == true){
                                    items.push(list[i])
                                }
                            }
                            if(items.length == 0){
                                app.toast('无选中项');
                                return;
                            }
                            app.confirm({
                                msg: '是否取消回报？',
                                ok: function (e) {
                                    app.ajax({
                                        xurl: "api/wx/gwat600/reconfirmlist",
                                        xdata: {
                                            items :JSON.stringify(items)
                                        },
                                        cb: function (result) {
                                            for(var i=0;i<result.data.data.length;i++){
                                                for(var j=0;j<items.length;j++){
                                                    if(items[j].GWCVDOCNO == result.data.data[i].GWCVDOCNO){
                                                        list.remove(items[j]);
                                                    }
                                                }
                                            }
                                            if (result.ok) {
                                                app.toast('批量取消回报成功');
                                            }else{
                                                app.toast(result.data.message);
                                            }
                                        }
                                    });
                                }
                            });
                        }
                    }
                });
            });

            mui('#scroll1,#scroll2,#scroll').scroll({
                indicators: true //是否显示滚动条
            });
        },
        _initRefresh: function () { // 实例化刷新组件
            if (self._refreshIds.length == 0) {
                self._refreshIds = ['scroll1', 'scroll2', 'scroll'];
            }
            this._super(win);
        },
        _search:function(d){
            self.searchData.keyword = d.keyword.trim();
            self._refresh();
        },
        _refreshCb: function (goods) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: "api/wx/gwat600/getGwcvDatas",
                // xtime: '1d',
                xdata: {
                    page:goods.page +1,
                    limit: goods.limit,
                    GWCSACTI: goods.type.replace('scroll', ''),
                    GWAA003:app.cookie('_WX_ACCOUNT_'),//微信号
                    keyword:self.searchData.keyword
                },
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data;
                        for(var i=0;i<data.data.length;i++){
                            data.data[i].checked = false;
                            data.data[i].GWAA003 = app.cookie('_WX_ACCOUNT_');
                        }
                        goods.data.pushArray(data.data, goods.page == 0);

                        _super({
                            obj: goods,
                            dataLen: data.data.length,
                            nodata: self._refreshIndex == 0 ? '无未回报订单...' : (self._refreshIndex == 1 ? '无已回报订单...' :'无订单...')
                        });
                    }
                }
            });
        },
        _slide:function (i) {
            footData.index=i;
            self._refresh();
        },
        setValue: function(item){
            var items = self._getRefreshObj().data;
            for(var i=0;i<items.length;i++){
                if(items[i].GWCS010 == item.GWCS010 && items[i].GWCS008 == item.GWCS008
                    && items[i].GWCS001 == item.GWCS001 && items[i].GWCS019 == item.GWCS019){
                    items[i].GWCV006 = item.GWCV006;
                    items[i].GWCV009 = item.GWCV009;
                    items[i].GWCV010 = item.GWCV010;
                    items[i].GWCV050 = item.GWCV050;
                    Vue.set(items,i,items[i]);
                }
            }
        }
    });

    return new gwat600();

});